// pages/modifywatchar/modifywatchar.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: '',
    phone: '',
    identity: '',
    modifyviewer:'',
    modifyphone:"",
    modifyidentity:""
  },
  nameBlur(e) {
    console.log("@@@@@@@@@@@@@@@@@@")
    var value1 = e.detail.value
    this.setData({
      name: value1
    })
    console.log(this.data.name)
  },
  phoneBlur(e) {
    console.log("@@@@@@@@@@@@@@@@@@")
    var value2 = e.detail.value
    this.setData({
      phone: value2
    })
    console.log(this.data.phone)
  },
  identityBlur(e) {
    console.log("@@@@@@@@@@@@@@@@@@")
    var value3 = e.detail.value
    this.setData({
      identity: value3
    })
    console.log(this.data.identity)
  },

  //修改观影人
  modifywatcher: function (e) {
    let self = this;
    let userInfo = app.globalData.userInfo;
    wx.request({
      url: "http://localhost:3000/updateViewer",
      method: 'POST',
      data: {
        userName: userInfo.nickName,
        viewer: self.data.modifyviewer,
        viewered: self.data.name || self.data.modifyviewer,
        userPhone: self.data.phone || self.data.modifyphone,
        userIdentityCard: self.data.identity || self.data.modifyidentity
      },
      success(res) {
        console.log("111111111")
        console.log(res.data)
        
          wx.navigateTo({
            url: "/pages/watch/watch"
          })
        wx.showToast({
          title: '修改成功',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _self = this;
      wx.getStorage({
        key: 'modifyviewer',
        success: function(res) {
          console.log('name获取成功')
          console.log(res.data)
          let viewer=res.data
          _self.setData({
            modifyviewer:viewer
          })
          console.log(_self.data.modifyviewer)
        },
      })
    wx.getStorage({
      key: 'modifyphone',
      success: function (res) {
        console.log('tel获取成功')
        console.log(res.data)
        let userphone = res.data
        _self.setData({
          modifyphone: userphone
        })
        console.log(_self.data.modifyphone)
      },
    })
    wx.getStorage({
      key: 'modifyidentity',
      success: function (res) {
        console.log('identity获取成功')
        console.log(res.data)
        let identity = res.data
        _self.setData({
          modifyidentity: identity
        })
        console.log(_self.data.modifyidentity)
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})